package com.seal.commons.generator.enums;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * JDBC Types转换Java Types
 * 
 */
public enum JavaType {
	STRING("String", ""),
	CHAR("String", ""),
	VARCHAR("String", ""),
	VARCHAR2("String", ""),
	LONGVARCHAR("String", ""),
	TEXT("String", ""),
	MEDIUMTEXT("String", ""),
	LONGTEXT("String", ""),
	NUMERIC("BigDecimal", "java.math.BigDecimal"),
	DECIMAL("BigDecimal", "java.math.BigDecimal"),
	BIT("Boolean", ""),
	TINYINT("Integer", ""),
	SMALLINT("Short",""),
	INTEGER("Integer",""),
	BIGINT("Long",""),
	NUMBER("Long",""),
	REAL("Float",""),
	FLOAT("Double",""),
	DOUBLE("Double",""),
	BINARY("String",""),
	VARBINARY("byte[]",""),
	LONGVARBINARY("byte[]",""),
	MEDIUMBLOB("byte[]",""),
	BLOB("byte[]",""),
	CLOB("String",""),
	DATE("LocalDate","java.time.LocalDate"),
	DATETIME("LocalDateTime","java.time.LocalDateTime"),
	TIME("LocalTime","java.time.LocalTime"),
	TIMESTAMP("LocalDateTime","java.time.LocalDateTime"),
	INT("Integer","");

	static Logger LOGGER = LoggerFactory.getLogger(JavaType.class);
	
	private String typeName;

	private String packageImport;

	private JavaType(String typeName, String packageImport) {
		this.typeName = typeName;
		this.packageImport = packageImport;
	}

	public String getTypeName() {
		return typeName;
	}

	public String getPackageImport() {
		return packageImport;
	}

	public static String getPackageImport(String javaType){
		for(JavaType temp: JavaType.values()){
			if(temp.getTypeName().equals(javaType)){
				return temp.getPackageImport();
			}
		}
		return "";
	}



	public static String getJavaType(String sqlType){
		String t = sqlType.toLowerCase();
		if (t.contains("char")) {
			return STRING.getTypeName();
		} else if (t.contains("bigint")) {
			return BIGINT.getTypeName();
		} else if (t.contains("tinyint(1)")) {
			return "Boolean";
		} else if (t.contains("int")) {
			return INTEGER.getTypeName();
		} else if (t.contains("text")) {
			return STRING.getTypeName();
		} else if (t.contains("bit")) {
			return "Boolean";
		} else if (t.contains("decimal")) {
			return DECIMAL.getTypeName();
		} else if (t.contains("clob")) {
			return CLOB.getTypeName();
		} else if (t.contains("blob")) {
			return BLOB.getTypeName();
		} else if (t.contains("binary")) {
			return BINARY.getTypeName();
		} else if (t.contains("float")) {
			return FLOAT.getTypeName();
		} else if (t.contains("double")) {
			return DOUBLE.getTypeName();
		} else if (t.contains("json") || t.contains("enum")) {
			return STRING.getTypeName();
		} else if (t.contains("datetime")){
			return DATETIME.getTypeName();
		}else if (t.contains("date")){
			return DATE.getTypeName();
		}else if(t.contains("time")){
			return TIME.getTypeName();
		}else if(t.contains("timestamp")){
			return TIMESTAMP.getTypeName();
		}
		return STRING.getTypeName();
	}


}
